import request from "@/utils/request";

// const USER_BASE_URL = "/api/v1/users";
const USER_BASE_URL = "/core/tProdHead";

const planDeliverGoodsApi = {
  /**
   * 查询生产单
   *
   * @param queryParams 查询参数
   */
  getPage(queryParams: planDeliverGoodsPageQuery) {
    let query = encodeURIComponent(JSON.stringify({ statusList: [0], ...queryParams }));
    return request<any, PageResult<planDeliverGoodsPageQuery[]>>({
      url: `/core/tSalesDelivery/getTSalesDeliveryList?object=${query}`,
      method: "get",
    });
  },

  /*
  /**
   * 删除生产单
   *
   * @param id id
   */

  deleteById(id: number) {
    return request<any, any>({
      url: `${USER_BASE_URL}/delTProdMachine`,
      method: "post",
      data: {
        id,
      },
    });
  },

  /*
   * 修改生产单
   * @param data 生产单信息
   */

  update(data: any) {
    return request<any, any>({
      url: `${USER_BASE_URL}/saveOrUpdateTProdMachine`,
      method: "post",
      data,
    });
  },

  //确认
  makeSure(id: any) {
    return request<any, any>({
      url: `/core/tSalesDelivery/saveOrUpdateTSalesDelivery`,
      method: "post",
      data: id,
    });
  },

  getTypePage(queryParams: any) {
    let query = encodeURIComponent(JSON.stringify({ ...queryParams }));
    return request<any, any>({
      url: `/core/product/getProductList?object=${query}`,
      method: "get",
    });
  },

  //详情
  detailList(queryParams: any) {
    return request<any, any>({
      url: `/core/tSalesDelivery/getTSalesDeliveryDetailByCode?parentCode=${queryParams}`,
      method: "get",
    });
  },

  addformData(queryParams: any) {
    return request<any, any>({
      url: `/core/tSalesDelivery/saveOrUpdateTSalesDelivery`,
      method: "post",
      data: queryParams,
    });
  },

  delFun(queryParams: any) {
    return request<any, any>({
      url: `/core/tSalesDelivery/delTSalesDelivery`,
      method: "post",
      data: queryParams,
    });
  },

  /**
   * 审核
   * @param
   */

  approvalTProdHead(data: { id: number; status: number; remark: string }) {
    return request<any, any>({
      url: `${USER_BASE_URL}/approvalTProdHead`,
      method: "post",
      data,
    });
  },
  getOptionsPage(queryParams: any): Promise<any> {
    return request<any, any>({
      url: `/core/company/list`,
      method: "post",
      data: {
        ...queryParams,
        isVendor: 0,
      },
    });
  },
};

export default planDeliverGoodsApi;

/*生产单搜索*/
export interface planDeliverGoodsPageQuery extends PageQuery {
  /* 生产单ID*/
  id?: number;
  /* 送货单号*/
  code?: string;
  /* 客户名称*/
  companyName?: string;
  /* 客户编码*/
  companyCode?: string;
  /* 交付日期*/
  deliveryDate?: string;
  /* 单据日期*/
  timeScopes?: string;
  /* 订单号*/
  parentCode?: string;
  /* 创建时间*/
  createDate?: string;
  statusList?: number[];
  status?: string;
}

export interface planDeliverGoodsPageVO {
  /* 生产单ID*/
  id?: number;
  /* 送货单号*/
  code?: string;
  /* 客户名称*/
  companyName?: string;
  /* 客户编码*/
  companyCode?: string;
  /* 交付日期*/
  deliveryDate?: string;
  /* 单据日期*/
  issueDate?: string;
  /* 订单号*/
  parentCode?: string;
  /* 创建时间*/
  createDate?: string;
  statusList?: number[];
  qty?: number;
  status?: string;
}
